package jangdolbaeng2.customer.action;

import java.util.List;
import java.util.Map;

import jangdolbaeng2.customer.dao.CustomerDAO;
import jangdolbaeng2.vo.CustomerVO;
import jangdolbaeng2.vo.ZipcodeVO;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class CustomerAction  extends ActionSupport implements SessionAware{
	private CustomerVO customer;
	private Map<String, Object> session;
	private String customer_id;
	private String password;
	private boolean result;
	
	private String searchText;
	private List<ZipcodeVO> zipList;
	private boolean idCheck;	//아이디 중복체크 
	
	//로그인 처리
	public String login() throws Exception {
		customer = new CustomerDAO().getCustomer(customer_id);
		System.out.println("Action1 : " + customer_id);
		if(customer != null && customer.getPassword().equals(password)){
			session.put("customer_id", customer_id);
			System.out.println("Action2 : " + customer_id);
			result = true;
		} else {
			result = false;
		}
		return SUCCESS;
	}
	
	//로그아웃 처리
	public String logout() throws Exception{
		session.remove("customer_id");
		return SUCCESS;
	}
	
	//아이디 중복체크
	public String idCheck() throws Exception{
		customer = new CustomerDAO().getCustomer(searchText);
		
		if(customer == null){
			idCheck = true;		//true면 중복된 아이디가 없음.
			customer_id = searchText;
		} else {
			customer_id = customer.getCustomer_id();
			idCheck = false;
		}
		return SUCCESS;
	}
	
	//회원정보 가져오기
	public String getCustom() throws Exception {
		new CustomerDAO().getCustomer(customer_id);
		return SUCCESS;
	}
	
	//우편번호 검색
	public String zipcode() throws Exception{
		zipList = new CustomerDAO().selectZip(searchText);
		return SUCCESS;
	}
	
	//회원 등록
	public String insertMember() throws Exception{
		new CustomerDAO().insertCustomer(customer);
		return SUCCESS;
	}


	//getter & setter
	public CustomerVO getCustomer() {
		return customer;
	}

	public void setCustomer(CustomerVO customer) {
		this.customer = customer;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public String getCustomer_id() {
		return customer_id;
	}

	public void setCustomer_id(String customer_id) {
		this.customer_id = customer_id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isResult() {
		return result;
	}

	public void setResult(boolean result) {
		this.result = result;
	}

	public String getSearchText() {
		return searchText;
	}

	public void setSearchText(String searchText) {
		this.searchText = searchText;
	}

	public List<ZipcodeVO> getZipList() {
		return zipList;
	}

	public void setZipList(List<ZipcodeVO> zipList) {
		this.zipList = zipList;
	}

	public boolean isIdCheck() {
		return idCheck;
	}

	public void setIdCheck(boolean idCheck) {
		this.idCheck = idCheck;
	}
	
}
